package com.ztk.threadbasic.controller;

import com.alibaba.fastjson.JSON;
import com.ztk.threadbasic.dto.FinancialDataDto;
import com.ztk.threadbasic.excel.CompanyVO;
import com.ztk.threadbasic.result.ExcelResult;
import com.ztk.threadbasic.service.ExcelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.InputStreamSource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 处理excel的接口
 */
@Slf4j
@RestController
@RequestMapping("/excel")
public class ExcelController {

    @Autowired
    private ExcelService excelService;

    @RequestMapping("/upload")
    public ExcelResult uploadExcel(@RequestParam("file")MultipartFile file) {
        return excelService.uploadExcel(file);
    }

    @RequestMapping("/download")
    public ResponseEntity<InputStreamResource> downloadExcel(HttpServletResponse response,
                                                             @RequestParam("budgetAgency") String budgetAgency,
                                                             @RequestParam("budgetDate") String budgetDate) {
        return excelService.downloadExcel(response, budgetAgency, budgetDate);
    }


    @RequestMapping("/test")
    public String test() {
        return "success";
    }


    public static void main(String[] args) {
        LocalDate financialStartDateInOb = LocalDate.of(2024, 12, 29);
        LocalDate currentFinanceDataDateTime = LocalDate.of(2025, 1, 3);
        long between = ChronoUnit.YEARS.between(financialStartDateInOb, currentFinanceDataDateTime);
        System.out.println(between);
    }
}
